
package com.ruoyi.web.controller.app;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.TAccountRecordsMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TAccountRecords;
import com.ruoyi.system.service.ITAccountRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 开户记录Controller
 * 
 * @author ruoyi
 * @date 2024-06-16
 */
@RestController
@RequestMapping("/system/accountRecords")
public class TAccountRecordsController extends BaseController
{
    @Autowired
    private ITAccountRecordsService tAccountRecordsService;
    @Autowired
    private TAccountRecordsMapper tAccountRecordsMapper;

    /**
     * 合计
     */
    @PostMapping("/sum")
    public AjaxResult sum(@RequestBody TAccountRecords tAccountRecords){
        Map<String,Object> map = new HashMap<>();
        map.put("amount",tAccountRecordsMapper.amountByAll(tAccountRecords));
        return AjaxResult.success(map);
    }

    /**
     * 查询开户记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:accountRecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(TAccountRecords tAccountRecords)
    {
        startPage();
        tAccountRecords.setUid(getUserId());
        List<TAccountRecords> list = tAccountRecordsService.selectTAccountRecordsList(tAccountRecords);
        return getDataTable(list);
    }

    /**
     * 查询开户记录列表(给管理看)
     */
    @PreAuthorize("@ss.hasPermi('system:accountData:list')")
    @GetMapping("/adminList")
    public TableDataInfo adminList(TAccountRecords tAccountRecords)
    {
        startPage();
        List<TAccountRecords> list = tAccountRecordsService.selectTAccountRecordsList(tAccountRecords);
        return getDataTable(list);
    }

    /**
     * 导出开户记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:accountRecords:export')")
    @Log(title = "开户记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TAccountRecords tAccountRecords)
    {
        List<TAccountRecords> list = tAccountRecordsService.selectTAccountRecordsList(tAccountRecords);
        ExcelUtil<TAccountRecords> util = new ExcelUtil<TAccountRecords>(TAccountRecords.class);
        util.exportExcel(response, list, "开户记录数据");
    }

    /**
     * 获取开户记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:accountRecords:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tAccountRecordsService.selectTAccountRecordsById(id));
    }

    /**
     * 新增开户记录
     */
    @PreAuthorize("@ss.hasPermi('system:accountRecords:add')")
    @Log(title = "开户记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAccountRecords tAccountRecords)
    {
        tAccountRecords.setUid(getUserId());
        return toAjax(tAccountRecordsService.insertTAccountRecords(tAccountRecords));
    }

    /**
     * 修改开户记录
     */
    @PreAuthorize("@ss.hasPermi('system:accountRecords:edit')")
    @Log(title = "开户记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAccountRecords tAccountRecords)
    {
        tAccountRecords.setUid(getUserId());
        return toAjax(tAccountRecordsService.updateTAccountRecords(tAccountRecords));
    }

    /**
     * 删除开户记录
     */
    @PreAuthorize("@ss.hasPermi('system:accountRecords:remove')")
    @Log(title = "开户记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tAccountRecordsService.deleteTAccountRecordsByIds(ids));
    }

    @Autowired
    private SysUserMapper sysUserMapper;
    /**
     * 获取投手信息
     */
    @GetMapping("/getPeoples")
    public AjaxResult getPeoples(){

        SysUser sysUser = new SysUser();
        return AjaxResult.success(sysUserMapper.selectUserList(sysUser));
    }
}
